<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:include="common/header" />
<body>

<div class="login">
    <div class="message">重置密码</div>
    <div id="darkbannerwrap"></div>
	<input name="action" value="login" type="hidden">
	<input id="loginName" name="username" placeholder="邮箱" required="" type="text">
	<hr class="hr15">
	<input id="password" name="password" placeholder="密码" required="" type="password">
	<hr class="hr15">
	<input id="confirmPassword" name="confirmPassword" placeholder="确认密码" required="" type="password">
	<hr class="hr15">
	<input id="reset" value="下一步" style="width:100%;" type="submit">
</div>
</body>
<link th:href="@{/resources/css/login.css}" type="text/css" rel="stylesheet">
<script>
    function isEmail(str){
        var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
        return reg.test(str);
    }

    function verify() {
        var loginName = $('#loginName').val();
        var password = $('#password').val();
        var confirmPassword = $('#confirmPassword').val();
        if(!isEmail(loginName)) {
            winTip('邮箱地址不正确！', false);
            return false;
        }
        if( !(password.length>=8 && password.length<=20 && confirmPassword.length>=8 && confirmPassword.length<=20) ) {
            winTip('密码在【8-20】之间！', false);
            return false;
        }
        if( !(password==confirmPassword) ) {
            winTip('密码不匹配！', false);
            return false;
        }
        return true;
    }

    $('#reset').click(function () {
        //验证
        if(verify()) {
            var user = {
                "loginName": $('#loginName').val(),
                "password": $('#password').val()
            };
            loading("请稍等，正在验证激活码!");
            $.getJSON("/forgetPasswordActivateCode", user, function (data) {
                closeLoading();
                if (data.code == 1) {
                    location.href = "/resetActivate";
                } else {
                    winTip('获取激活码失败！请重新获取！', false);
                }
            });
        }
    });
</script>
</html>